package com.cheng.learn.leetcode;

/**
 * @description: 找到excel 对应列名的序号
 * @author: ChengHaiZhu
 * @create: 2021-03-21 00:30
 **/
public class TitleToNumber171 {

    /**
     * A->1;B->2,,,z->26,相当于26进制
     * @param columnTitle
     * @return
     */
    public int titleToNumber(String columnTitle) {
        int ans = 0;
        for(int i=0;i < columnTitle.length();i++) {
            int num = columnTitle.charAt(i) - 'A' + 1;
            ans = ans * 26 + num;
        }
        return ans;
    }
}
